package lib

import (
	"fmt"
	"github.com/PuerkitoBio/goquery"
)

func Get_lrtk_Url(start, end, nub int) {
	Basedir = "../lanrentuku_jiaoben/"

	job := make(chan *Job, nub)
	rs := make(chan int)

	go func() {
		for i := start; i > end; i-- {
			job <- &Job{"http://www.lanrentuku.com/js/qita-" + fmt.Sprint(i) + ".html", i}
		}

		close(job)
	}()
	for i := 0; i < nub; i++ {
		go func() {

			for item := range job {
				d, err := goquery.NewDocumentGBK(item.Url)
				if err != nil {
					fmt.Println("Search webpage err:%s", err)
					return
				}
				filename := d.Find(".content-js .l span").Text()
				fmt.Println(filename)
				Mkdir(Basedir + filename)
				//Downlaod("http://d.lanrentuku.com/down/js/daohang-"+fmt.Sprint(item.Nub)+"/index.jpg", filename)
				Downlaod("http://www.lanrentuku.com/js/d"+fmt.Sprint(item.Nub)+".zip", filename)

			}
			rs <- 0
		}()
	}
	for i := 0; i < nub; i++ {
		<-rs
	}
}
